#ifndef __PID_MODULE_H__
#define __PID_MODULE_H__

#include "common.h"
#include "global_config.h"

/* PID controller indices */
#define PID_HEATER     0
#define PID_COMPRESSOR 1
#define PID_CONTROLLERS 2

/* PID control modes */
typedef enum {
    PID_MODE_MANUAL = 0,
    PID_MODE_AUTO,
    PID_MODE_CASCADE
} pid_mode_t;

/* PID message types */
typedef enum {
    PID_MSG_OUTPUT_UPDATE = 1,
    PID_MSG_SETPOINT_CHANGE,
    PID_MSG_PARAMETER_UPDATE,
    PID_MSG_MODE_CHANGE
} pid_msg_type_t;

/* PID parameter structure */
typedef struct {
    uint8_t controller_id;
    float kp;
    float ki;
    float kd;
    float setpoint;
    float output_min;
    float output_max;
} pid_parameters_t;

/* Function declarations */
rt_err_t pid_module_init(void);
void pid_thread_entry(void *parameter);
rt_err_t pid_set_parameters(uint8_t controller_id, float kp, float ki, float kd, 
                           float output_min, float output_max);
rt_err_t pid_set_setpoint(uint8_t controller_id, float setpoint);
rt_err_t pid_set_mode(uint8_t controller_id, pid_mode_t mode);
rt_err_t pid_set_auto_control(rt_bool_t enable);
float pid_get_output(uint8_t controller_id);
float pid_get_setpoint(uint8_t controller_id);
rt_bool_t pid_get_auto_control(void);

/* External configuration access */
extern pid_config_t *pid_get_config(void);

#endif /* __PID_MODULE_H__ */